<?php
class Pagination
{

    /*
     *  $page = 2; //当前页数
        $currentPage = $page<=1?0 :$page-1;
        $pageSize =10  ; //每页显示多少条
        $offset = $currentPage*$pageSize;
     *public function __construct($page,$pageSize){
        $this->page=$page;
        $this->pageSize=$pageSize;

    }

     * */

    private $page=1;//当前页数
    private $pagesize=10;//每页显条数


    //数组赋值
    public function __construct(array $data) {
        foreach ($data as $key => $value) {
            if (property_exists($this, $key)) {
                $this->$key = $value;
            }
        }
    }

    //获取原始数据的总条数，统计原始数据数量
    public function getRawDataCount($rawData)
    {
        return count($rawData);

    }

    public function getPage()
    {
        return $this->page;

    }

    public function getPageSize()
    {
        return $this->pagesize;
    }

    public function getPageNum(){
        return $this->getPageSize() * ($this->getPage()-1);
    }

    public function getOffset()
    {
        $offset = ($this->getPage() - 1) * $this->getPageSize();
        return $offset;
    }

    //物理分页，数组分页,只支持单表，适合小数据
    public function setList($data)
    {
        $currentPage = $this->getPage()<=1?0 :$this->getPage()-1;
        $offset = $currentPage*$this->getPageSize();
        return array_slice($data,$offset,$this->getPageSize());
    }


}



